package comxin.demo1.jdbcdemo;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class jdbcconnection_02 {
    public static void main(String[] args) {
        Connection conn=null;
        try {

            InputStream is = jdbcconnection_02.class.getClassLoader().getResourceAsStream("jdbc.properties");
            Properties properties=new Properties();
            properties.load(is);
            String driverClass=properties.getProperty("driverClass");
            String url = properties.getProperty("url");
            String username=properties.getProperty("username");
            String password=properties.getProperty("password");
            Class.forName(driverClass);
            conn = DriverManager.getConnection(url, username, password);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println(conn);
    }
}
